{extend name='app' /}
{block name='title'}添加项目{/block}

{block name="stylesheet"}
<link href="{__ADMIN__}/css/plugins/summernote/summernote-bs4.css" rel="stylesheet">
<link href="{__ADMIN__}/css/plugins/dropzone/basic.css" rel="stylesheet">
<link href="{__ADMIN__}/css/plugins/dropzone/dropzone.css" rel="stylesheet">
<style>
    .dz-image img {
        width: 100%;
    }

    .dz-size {
        display: none;
    }

    .progress{
        margin-top:2px;
        width: 200px;
        height: 14px;
        margin-bottom: 10px;
        overflow: hidden;
        background-color: #f5f5f5;
        border-radius: 4px;
        -webkit-box-shadow: inset 0 1px 2px rgba(0,0,0,.1);
        box-shadow: inset 0 1px 2px rgba(0,0,0,.1);
    }
    .progress-bar{
        background-color: rgb(92, 184, 92);
        background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.14902) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.14902) 50%, rgba(255, 255, 255, 0.14902) 75%, transparent 75%, transparent);
        background-size: 40px 40px;
        box-shadow: rgba(0, 0, 0, 0.14902) 0px -1px 0px 0px inset;
        box-sizing: border-box;
        color: rgb(255, 255, 255);
        display: block;
        float: left;
        font-size: 12px;
        height: 20px;
        line-height: 20px;
        text-align: center;
        transition-delay: 0s;
        transition-duration: 0.6s;
        transition-property: width;
        transition-timing-function: ease;
        width: 266.188px;
    }
</style>
{/block}

{block name="breadcrumb"}
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>添加项目</h2>
        <ol class="breadcrumb">
            <li class="breadcrumb-item">
                <a>项目管理</a>
            </li>
            <li class="breadcrumb-item">
                <a href="{$Think.config.admin.app_host}/admin/project">项目列表{$Think.config.admin.app_host}</a>
            </li>
            <li class="breadcrumb-item active">
                <strong>添加项目</strong>
            </li>
        </ol>
    </div>
</div>
{/block}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-title">
                    <h5>添加商品</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>

                <div class="ibox-content">
                    <form method="post" enctype="multipart/form-data" id="addForm">
                        <input type="radio" name="myradio" value="random_name" hidden checked=true/>

                        <div class="form-group row">
                            <label class="col-sm-2 control-label">名称 ：</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="name">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group row">
                            <label class="col-sm-2 control-label">主分类 ：</label>
                            <div class="col-sm-10">
                                <select class="chosen-select" name="category_id">
                                    {foreach $category as $key => $item}
                                        <option value="{$item['id']}">{$item['name']}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group row">
                            <label class="col-sm-2 control-label">标签 ：</label>
                            <div class="col-sm-10">
                                <select data-placeholder="   可多选" class="chosen-select" name="label_ids[]" multiple>
                                    {foreach $label as $item}
                                        <option value="{$item->id}">{$item->name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group row">
                            <label class="col-sm-2 control-label">下单等级 ：</label>
                            <div class="col-sm-10">
                                <select class="chosen-select" name="at_level">
                                    {foreach $level as $item}
                                        <option value="{$item->id}">{$item->name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>


                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">缩略图 ：</label>
                            <div class="col-sm-10">
                                <img src="{__ADMIN__}/dist/img/default-img.png" alt="" class="upload-file-alone">
                                <div class="custom-file">
                                    <input type="file" name="project_thumb" class="custom-file-input" onchange="custom_file_input($(this))">
                                    <span class="custom-file-label">选择文件</span>
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">视频文件列表 ：</label>
                            <div class="col-sm-10" id="ossfile">你的浏览器不支持flash,Silverlight或者HTML5！</div>
                            <input type="text" name="video" class="form-control" hidden id="index_video" readonly>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">视频上传 ：</label>
                            <div class="col-sm-10">
                                <div id="container">
                                    <a id="selectfiles" href="javascript:void(0);" class='btn'>选择文件</a>
                                    <a id="postfiles" href="javascript:void(0);" class='btn'>开始上传</a>
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>


                        <div class="form-group row">
                            <label class="col-sm-2 control-label">积分 ：</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="integral" value="0">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group row">
                            <label class="col-sm-2 control-label">考核及格分数 ：</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="num" value="0">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group row">
                            <label class="col-sm-2 control-label">简介 ：</label>
                            <div class="col-sm-10">
                                <textarea class="form-control" rows="4" name="describe"></textarea>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group row">
                            <label class="col-sm-2 control-label">详情 ：</label>
                            <div class="col-sm-10">
                                <textarea class="form-control summernote" rows="6" name="detail"></textarea>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group row">
                            <label class="col-sm-2 control-label">订单填写要求 ：</label>
                            <div class="col-sm-10">
                                <textarea class="form-control" rows="4" name="order_require"></textarea>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>


                        <div class="form-group row">
                            <label class="col-sm-2 control-label">热门推荐 ：</label>
                            <div class="col-sm-10">
                                <select class="chosen-select" name="new_status">
                                    <option value="0">否</option>
                                    <option value="1">是</option>
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group row">
                            <label class="col-sm-2 control-label">日结 ：</label>
                            <div class="col-sm-10">
                                <select class="chosen-select" name="type">
                                    <option value="0">否</option>
                                    <option value="1">是</option>
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">排序 ：</label>
                            <div class="col-sm-10">
                                <input type="number" class="form-control" name="sort" value="999">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>


                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">状态 ：</label>
                            <div class="col-sm-10">
                                <label class="lab-radio">
                                    <input type="radio" value="0" name="status"  checked="">待上线
                                </label>
                                <label class="lab-radio">
                                    <input type="radio" value="1" name="status">正常
                                </label>
                                <label class="lab-radio">
                                    <input type="radio" value="2" name="status">结束
                                </label>
                            </div>
                        </div>


                        <div class="form-group row">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-primary" type="button" onclick="add_goods($(this),'{$Think.config.admin.app_host}/admin/project')">
                                    保存
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script src="{__ADMIN__}/js/plugins/summernote/summernote-bs4.js"></script>
<script src="{__ADMIN__}/js/plugins/dropzone/dropzone.js"></script>
<script type="text/javascript" src="{__ADMIN__}/js/plugins/plupload-2.1.2/js/plupload.full.min.js"></script>
<script type="text/javascript" src="{__ADMIN__}/js/upload.js"></script>

<script>

    $(function () {
        $('.chosen-select').chosen({width: "100%", search_contains: true,});
    })

    function add_goods(that, url) {
        let form_id = that.parents('form').attr('id');
        let data = new FormData(document.getElementById(form_id));

        let loading = that.ladda();

        // 加载中按钮显示
        loading.ladda('start');

        let response = post_request(url, data);
        if (response.status == 1) {
            loading.ladda('stop');
            show_swal({msg: response.msg}, function () {
                window.location.href = response.data.redirect_url;
            });
        } else {
            let msg = response.msg
            if (!msg) {
                msg = '系统出错了';
            }
            show_tip('提示', msg, 'error');
            // 加载中按钮隐藏
            loading.ladda('stop');
        }
    }

</script>

<script>
    $(function () {
        $('.summernote').summernote({
            height: 300,
            callbacks: {
                onImageUpload: function (files, editor, welEditable) {
                    for (var i = files.length - 1; i >= 0; i--) {
                        sendFile(files[i], this);
                    }
                    // $(document.body).addClass("modal-open");
                },
                onImageUploadError: function () {
                    // $(document.body).addClass("modal-open");
                }
            },
        });

        function sendFile(file, el) {
            var url = '{$Think.config.admin.app_host}/admin/common/file';
            var data = new FormData();
            data.append("project_detail", file); // 表单名称

            let response = post_request(url, data);
            if (response.status == 1) {
                $(el).summernote('editor.insertImage', response.data.url, response.data.path);
            } else {
                show_tip('提示', response.msg, 'error');
            }
        }
    });
</script>
{/block}
